<script>
	$(function(){
		Namespace.register("EBCMS.[namespace]");
		EBCMS.[namespace].queryParams = {
			page:1,
			rows:20,
			sort:'sort',
			order:'desc',
			__model:'guestbook',
		};
		EBCMS.[namespace].refresh = function refresh(p){
			if (p) {
				$.each(p, function(index, val) {
					if (typeof val == 'object') {
						EBCMS.[namespace].queryParams[index] = $.extend(EBCMS.[namespace].queryParams[index], p[index]);
						delete p[index];
					};
				});
				$.extend(EBCMS.[namespace].queryParams, p);
			};
			EBCMS.CORE.api({
				queryParams:EBCMS.[namespace].queryParams,
				tpl:'[namespace]-table',
				target:'#[namespace]_main',
				compileAfter:function(p){
					$('#[namespace]_main').find('.input_sort').focus(function(){
						EBCMS.[namespace].sortvalue = $(this).val();
					}).blur(function(){
						var $this = $(this);
						if ($this.val() != EBCMS.[namespace].sortvalue) {
							EBCMS.ACT.togglefield('{:U('Guestbook/resort')}',$this.data('id'),$this.val(),'[namespace]','resort');
						};
					});
					EBCMS.FN.renderPage('[namespace]',p.data.total);
				},
			});
		};
		EBCMS.[namespace].save = function save(id){
			EBCMS.CORE.get({
				url:'{:U('Guestbook/save')}',
				queryParams:{
					id:id,
				},
				target:'#lgModal .modal-content',
				loadAfter:function(data,p){
					$('#lgModal').modal('toggle');
				},
			});
		};
		EBCMS.[namespace].reply = function reply(id){
			EBCMS.CORE.get({
				url:'{:U('Guestbook/reply')}',
				queryParams:{
					id:id,
				},
				target:'#lgModal .modal-content',
				loadAfter:function(data,p){
					$('#lgModal').modal('toggle');
				},
			});
		};
		EBCMS.[namespace].refresh();
	});
</script>

<div class="header">
	<div class="header-title" onclick="EBCMS.[namespace].refresh();">留言管理</div>
</div>
<div class="body" id="[namespace]_main">
</div>
<div class="footer">
	<div id="[namespace]_page" class="footer-page"></div>
</div>

<script id="[namespace]-table" type="text/html">
	{{each rows as v n}}
	<div class="media articlelist">
		<div class="media-left">
			<div style="width:60px;">
				<img src="__IMAGE__/noavatar_middle.gif" alt="">
				<h5 class="text-center"><span class="label label-danger">{{v.nickname}}</span></h5>
			</div>
		</div>
		<div class="media-body">
			<div class="alert alert-info">
				<p>{{v.content}}</p>
				<p>联系电话：{{v.mobile}} 留言时间：{{v.update_time}}</p>
			</div>
			{{if v.reply}}
			<div class="media">
				<div class="media-body">
					<p class="alert alert-danger">{{v.reply}}</p>
				</div>
				<div class="media-right">
					<div style="width:60px;">
						<img src="__IMAGE__/nb.jpg" alt="">
					</div>
				</div>
			</div>
			{{/if}}
		</div>
		<div class="media-right">
			<div style="width:48px;">
				<div class="btn-group-vertical btn-group-sm" role="group" aria-label="...">
					{{if access(0,'[namespace]','lock')}}
						{{if v.locked==1}}
						<a class="btn btn-default" href="javascript:EBCMS.ACT.lock('{:U('Guestbook/lock')}','{{v.id}}','0','[namespace]');">已锁</a>
						{{else}}
						<a class="btn btn-default" href="javascript:EBCMS.ACT.lock('{:U('Guestbook/lock')}','{{v.id}}','1','[namespace]');">未锁</a>
						{{/if}}
					{{/if}}
					{{if access(v.locked,'[namespace]','status')}}
						{{if v.status==1}}
						<a class="btn btn-default" href="javascript:EBCMS.ACT.status('{:U('Guestbook/status')}','{{v.id}}','0','[namespace]');">已审</a>
						{{else}}
						<a class="btn btn-default" href="javascript:EBCMS.ACT.status('{:U('Guestbook/status')}','{{v.id}}','1','[namespace]');">未审</a>
						{{/if}}
					{{/if}}
					{{if access(v.locked,'[namespace]','save')}}
					<a class="btn btn-default" href="javascript:EBCMS.[namespace].save('{{v.id}}');">编辑</a>
					{{/if}}
					{{if access(v.locked,'[namespace]','reply')}}
					<a class="btn btn-default" href="javascript:EBCMS.[namespace].reply('{{v.id}}');">回复</a>
					{{/if}}
					{{if access(v.locked,'[namespace]','delete')}}
					<a class="btn btn-default" href="javascript:EBCMS.ACT.del('{:U('Guestbook/delete')}','{{v.id}}','[namespace]');">删除</a>
					{{/if}}
					{{if access(0,'admin_recommend','push')}}
					<a class="btn btn-default" href="javascript:EBCMS.CORE.recommend('guestbook','{{v.id}}');" role="button">推送</a>
					{{/if}}
				</div>
			</div>
		</div>
	</div>
	{{/each}}
</script>